/**
 * Created by novem on 2015/10/20.
 */
window.onload=function(){
    var supplierId = $.getUrlParam("supplierId");
    var url = getUrl();
    $.jsonp({
        url: 'http://'+url+'/api/supplier/supplier_detail-'+supplierId,
        data: {},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            data.supplier.distance = $.getUrlParam("distance");
            $("#chat").attr("onclick","easeMobGoChat("+data.supplier.telphone+")");
            $("#url").attr("href","jiudian_tijiaodingdan.html?supplierId="+supplierId);
            var complied_tpl01 = juicer($("#jd_detail01").text());
            var html01 = complied_tpl01.render(data);
            $(".order01").append(html01);
            var complied_tpl02 = juicer($("#jd_detail02").text());
            var html02 = complied_tpl02.render(data);
            $("#order02").append(html02);
            var complied_tpl03 = juicer($("#jd_detail03").text());
            var html03 = complied_tpl03.render(data);
            $("#order03").append(html03);
            $.jsonp({
                url: 'http://'+url+'/api/supplier/comment_list-'+supplierId,
                data: {},
                callbackParameter: "callback",
                success: function (data, textStatus, xOptions) {
                    $("#all_pj").attr("href","jiudian_allpingjia.html?supplierId=" + supplierId);
                    var len = data.arrays.length-1;
                    if(len<0){
                        var html = "";
                    }else {
                        //var unixTimestamp = new Date(data.arrays[0].createTime * 1000);
                        //data.arrays[0].createTime = unixTimestamp.toLocaleString();
                        var html = '<li class="ui-border-b"><div class="ui-comment-list-detail clearfix"><div class="ui-comment-list-user clearfix"><div class="ui-comment-list-avatar">' +
                            '<img src="' + data.arrays[0].photo + '" width="40" height="40" alt=""></div>' +
                            '<div class="ui-comment-list-info"><p>' + data.arrays[0].nickName + '</p><p class="ui-txt-muted">' + getTime(data.arrays[0].createTime)+ '</p></div></div>' +
                            '<div class="ui-comment-list-star"><span class="ui-star ui-star-' + data.arrays[0].star + '"></span>' + data.arrays[0].star + '分</div></div>' +
                            '<div class="ui-comment-list-content">' +
                            '' + data.arrays[0].comment + '</div></li>';
                    }
                    $("#ui-comment-list").append(html);
                },
                error: function (xOptions, textStatus) {}
            });
        },
        error: function (xOptions, textStatus) {
        }
    });
}
function getTime(t){
    var nt = t*1000;
    var n = new Date(nt);
    return formatDate(n);
}
function formatDate(now)   {
    var   year=now.getFullYear();
    var   month=now.getMonth()+1;
    var   date=now.getDate();
    return   year+"-"+(month>=10?month:"0"+month)+"-"+(date>=10?date:"0"+date);
}